var footer = false;
var gc_id = getQueryString("gc_id");
var key = 4;
var order = getQueryString("order");

$(function() {
    get_list();
    $(window).scroll(
        function() {
            if ($(window).scrollTop() + $(window).height() > $(document)
                    .height() - 1) {
                get_list()
            }
        });
});
function get_list() {
    param = {};
    if (gc_id != "") {
        param.gc_id = gc_id
    }
    if (key != "") {
        param.key = key
    }
    if (order != "") {
        param.order = order
    }
    $.getJSON(ApiUrl + "/index.php?act=goods&op=product_list_category"
        + window.location.search.replace("?", "&"), param, function(e) {
        if (!e) {
            e = [];
            e.datas = [];
            e.datas.gc_name = '';
            e.datas.goods_list = [];
        }
        $("#category_name").html(e.datas.gc_name);
        $("#product_list").html(template.render("product_category", e.datas));
    })
}
function init_get_list(r,img_id) {
    key = r;
    setStyle(r,img_id);
    get_list()
}
function setImg(img_id){
    if($("#"+img_id).attr("src").indexOf("list_03.png")>-1 && $("#"+img_id).css("display")=='inline'){//desc ---> asc
        order = 1;
        $("#"+img_id).attr("src","../images/list_031.png");
    }else{
        order = 0;
        $("#"+img_id).attr("src","../images/list_03.png");
    }
}
function setStyle(r,img_id){//1:xiaoliang; 3:jiage; 4:shouyi
    setImg(img_id);
    if(r==1){
        if (!$("#xiaoliang").hasClass("index")) {
            $("#xiaoliang").addClass("index")
        }
        $("#jiage").removeClass("index")
        $("#shouyi").removeClass("index")
    }else if(r==3){
        if (!$("#jiage").hasClass("index")) {
            $("#jiage").addClass("index")
        }
        $("#xiaoliang").removeClass("index")
        $("#shouyi").removeClass("index")
    }else if(r==4){
        if (!$("#shouyi").hasClass("index")) {
            $("#shouyi").addClass("index")
        }
        $("#jiage").removeClass("index")
        $("#xiaoliang").removeClass("index")
    }
}